home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / xv / xvinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  10.0 KB  |  363 lines

  1. /* XView info stuff.
  2.    Copyright (C) 1995 Jakub Jelinek.
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <config.h>
  19. #include <xview/xview.h>
  20. #include <xview/frame.h>
  21. #include <xview/panel.h>
  22. #include <xview/canvas.h>
  23. #include <xview/svrimage.h>
  24. #include <xview/cms.h>
  25. #include <xview/font.h>
  26. #include <xview/scrollbar.h>
  27.  
  28. #include "fs.h"
  29. #include "dir.h"
  30. #include "panel.h"
  31. #include "dlg.h"
  32. #include "widget.h"
  33. #include "info.h"
  34. #include "main.h"
  35. #include "util.h"
  36. #include "win.h"
  37. #include "xvmain.h"
  38.  
  39. #include "mc.icon"
  40.  
  41. extern Dlg_head *midnight_dlg;
  42.  
  43. static Cms infocms;
  44. Server_image mcimage;
  45.  
  46. void x_setup_info (void)
  47. {
  48.     int i;
  49.     
  50.     infocms = xv_create (XV_NULL, CMS,
  51.         CMS_SIZE, sizeof (mc_colors) / sizeof (Xv_singlecolor) + 9,
  52.         CMS_CONTROL_CMS, TRUE,
  53.         CMS_NAME, "infocms",
  54.         NULL);                                            
  55.     xv_set (infocms,
  56.         CMS_INDEX, 8,
  57.         CMS_COLOR_COUNT, sizeof (mc_colors) / sizeof (Xv_singlecolor),
  58.         CMS_COLORS, &mc_colors,
  59.         NULL);
  60.     xv_set (infocms,
  61.         CMS_INDEX, sizeof (mc_colors) / sizeof (Xv_singlecolor) + 8,
  62.         CMS_COLOR_COUNT, 1,
  63.         CMS_NAMED_COLORS, "black", NULL,
  64.         NULL);
  65.     mcimage = xv_create (XV_NULL, SERVER_IMAGE,
  66.         XV_WIDTH, mc_width,
  67.         XV_HEIGHT, mc_height,
  68.         SERVER_IMAGE_COLORMAP, "infocms",
  69.         SERVER_IMAGE_DEPTH, 8,
  70.         SERVER_IMAGE_X_BITS, mc_bits,
  71.         NULL);
  72. }
  73.  
  74. #if 0
  75. static void x_info_recalculate (Columnizer tile)
  76. {
  77.     int i, j, top = xv_get (tile, COLUMNIZER_N_COLUMNS);
  78.     int count = xv_get (tile, COLUMNIZER_N_ROWS), max, w;
  79.  
  80.     for (i = 0; i < top; i++) {
  81.         max = 0;
  82.         for (j = 0; j < count; j++) {
  83.             w = xv_get ((Rectobj) xv_get (tile, COLUMNIZER_POSITION, i, j),
  84.                 XV_WIDTH);
  85.             if (w > max)
  86.                 max = w;
  87.         }
  88.         for (j = 0; j < count; j++) {
  89.             xv_set ((Rectobj) xv_get (tile, COLUMNIZER_POSITION, i, j),
  90.                 XV_WIDTH, max,
  91.                 NULL);
  92.         }
  93.     }
  94. }
  95. #endif
  96.  
  97. void x_show_info (WInfo *info, struct my_statfs *s, struct stat *b)
  98. {
  99. #if 0
  100.     Canvas_shell canvas = (Canvas_shell) xv_get ((Bag) (info->widget.wdata),
  101.         XV_OWNER);
  102.     Columnizer tile = (Columnizer) xv_get ((Bag) (info->widget.wdata),
  103.         RECTOBJ_NTH_CHILD, 3); 
  104.     char buffer [100];
  105.     char *text;
  106.     char *p;
  107.     int i;
  108.     Xv_opaque win;
  109.     int w, h;
  110.     Scrollbar scrollbar;
  111.  
  112.     xv_set (canvas,
  113.         CANVAS_SHELL_DELAY_REPAINT, TRUE,
  114.         NULL);
  115.         
  116.     for (i = 0; i < 14; i++) {
  117.         text = buffer;
  118.         switch (i + 3) {
  119.             case 16:
  120.         if (s->nfree >0 || s->nodes > 0)
  121.                 sprintf (buffer, "%d (%d%%) of %d",
  122.                 s->nfree,
  123.                 s->total
  124.                 ? 100 * s->nfree / s->nodes : 0,
  125.                 s->nodes);
  126.             else
  127.                 text = "No node information";
  128.             break;
  129.     
  130.         case 15:
  131.         if (s->avail > 0 || s->total > 0){
  132.                 sprint_bytesize (buffer, s->avail, 1);
  133.                 p = strchr (buffer, 0);
  134.                 sprintf (p, " (%d%%) of ", s->total
  135.                 ? 100 * s->avail / s->total : 0);
  136.             p = strchr (buffer, 0);
  137.                 sprint_bytesize (p, s->total, 1);
  138.             } else
  139.                 text = "No space information";
  140.             break;
  141.  
  142.             case 14:
  143.         sprintf (buffer, "%s ", s->typename);
  144.         p = strchr (buffer, 0);
  145.             if ((unsigned) s->type != 0xffff && 
  146.                 (unsigned) s->type != 0xffffffff)
  147.                 sprintf (p, " (%Xh)", s->type);
  148.             break;
  149.  
  150.             case 13:
  151.         text = s->device;
  152.         break;
  153.         
  154.             case 12:
  155.                 text = s->mpoint;
  156.                 break;
  157.  
  158.             case 11:
  159.         text = file_date (b->st_atime);
  160.         break;
  161.     
  162.             case 10:
  163.         text = file_date (b->st_mtime);
  164.         break;
  165.     
  166.         case 9:
  167.         text = file_date (b->st_ctime);
  168.         break;
  169.     
  170.             case 8:
  171. #ifdef HAVE_ST_RDEV
  172.         if (b->st_rdev) {
  173.                 sprintf (buffer, "major: %d, minor: %d",
  174.                 b->st_rdev >> 8, b->st_rdev & 0xff);
  175.             xv_set (xv_get (tile, COLUMNIZER_POSITION, 0, i),
  176.                 DRAWTEXT_STRING, "Inode dev:",
  177.                 NULL);
  178.         } else {
  179.             xv_set (xv_get (tile, COLUMNIZER_POSITION, 0, i),
  180.                 DRAWTEXT_STRING, "Size:",
  181.                 NULL);
  182. #endif
  183.                 sprint_bytesize (buffer, b->st_size, 0);
  184.                 p = strchr (buffer, 0);
  185. #ifdef HAVE_ST_BLOCKS
  186.                 sprintf (p, " (%d blocks)", (int) b->st_blocks);
  187. #endif
  188. #ifdef HAVE_ST_RDEV                
  189.         }
  190. #endif
  191.         break;
  192.         
  193.         case 7:
  194.         sprintf (buffer, "%s/%s", get_owner (b->st_uid), 
  195.             get_group (b->st_gid));
  196.         break;
  197.     
  198.         case 6:
  199.         sprintf (buffer, "%d", b->st_nlink);
  200.         break;
  201.     
  202.         case 5:
  203.         sprintf (buffer, "%s (%o)",
  204.             string_perm (b->st_mode), b->st_mode & 07777);
  205.         break;
  206.     
  207.         case 4:
  208.         sprintf (buffer, "%Xh:%Xh", (int) b->st_dev, (int) b->st_ino);
  209.         break;
  210.     
  211.         case 3:
  212.             text = cpanel->dir.list [cpanel->selected].fname;
  213.             break;
  214.     }
  215.     xv_set (xv_get (tile, COLUMNIZER_POSITION, 1, i),
  216.         DRAWTEXT_STRING, text,
  217.         NULL);
  218.     }
  219.     
  220.     x_info_recalculate (tile);
  221.     
  222.     w = xv_get ((Bag) (info->widget.wdata), XV_WIDTH);
  223.     h = xv_get ((Bag) (info->widget.wdata), XV_HEIGHT);
  224.     
  225.         xv_set (canvas,
  226.             CANVAS_MIN_PAINT_WIDTH, w,
  227.             CANVAS_MIN_PAINT_HEIGHT, h,
  228.             NULL);
  229.  
  230.         OPENWIN_EACH_VIEW (canvas, win)
  231.             scrollbar = (Scrollbar) xv_get (canvas, OPENWIN_HORIZONTAL_SCROLLBAR, win);
  232.             if (scrollbar != XV_NULL)
  233.                 xv_set (scrollbar,
  234.                     SCROLLBAR_OBJECT_LENGTH, w,
  235.                     SCROLLBAR_PIXELS_PER_UNIT, 1,
  236.                     NULL);
  237.             scrollbar = (Scrollbar) xv_get (canvas, OPENWIN_VERTICAL_SCROLLBAR, win);
  238.             if (scrollbar != XV_NULL)
  239.                 xv_set (scrollbar,
  240.                     SCROLLBAR_OBJECT_LENGTH, h,
  241.                     SCROLLBAR_PIXELS_PER_UNIT, 1,
  242.                     NULL);
  243.         OPENWIN_END_EACH
  244.  
  245.     xv_set (canvas,
  246.         CANVAS_SHELL_DELAY_REPAINT, FALSE,
  247.         NULL);
  248. #endif        
  249. }
  250.  
  251. #ifndef VERSION
  252. #   define VERSION "undefined"
  253. #endif
  254.  
  255. #if 0
  256. void backevent_proc_seal (Xv_window, Event *, Canvas_shell, Rectobj);
  257. #endif
  258. int x_create_info (Dlg_head *h, widget_data parent, WInfo *info)
  259. {
  260. #if 0
  261.     Canvas canvas = 
  262.         (Canvas) x_get_parent_object ((Widget *) info, parent);
  263.     Bag tile;
  264.     Xv_opaque previous;
  265.     char buffer [50];
  266.     Drawtext text;
  267.     Columnizer tile1;
  268.     int i, height;
  269.     static char *names [] = { "File:", "Location:", "Mode:", "Links:", "Owner:",
  270.         "Size:", "Created:", "Modified:", "Accessed:", "Filesystem:", "Device:",
  271.         "Type:", "Free space:", "Free nodes:" };
  272.     
  273.     previous = xv_get (canvas, RECTOBJ_NTH_CHILD, 0);
  274.     
  275.     if (previous != XV_NULL)
  276.         xv_destroy_safe (previous);
  277.     
  278.     tile = xv_create (canvas, BAG,
  279.     XV_KEY_DATA, KEY_DATA_PANEL, info,
  280.     XV_KEY_DATA, KEY_DATA_PANEL_CONTAINER, xv_get (canvas, XV_OWNER),
  281.     RECTOBJ_EVENT_PROC, backevent_proc_seal,
  282.     XV_X, 5, 
  283.     XV_Y, 5,
  284.     XV_KEY_DATA, KEY_DATA_BOLD_FONT,
  285.         xv_find (canvas, FONT,
  286.             FONT_FAMILY, xv_get (xv_get (canvas, CANVAS_SHELL_FONT),
  287.                 FONT_FAMILY),
  288.             FONT_SIZE, xv_get (xv_get (canvas, CANVAS_SHELL_FONT),
  289.                 FONT_SIZE),
  290.             FONT_STYLE, FONT_STYLE_BOLD,
  291.             NULL),
  292.     NULL);
  293.     xv_set (canvas, 
  294.         XV_KEY_DATA, KEY_DATA_TILE, tile,
  295.         RECTOBJ_ACCEPTS_DROP, FALSE,
  296.     RECTOBJ_EVENT_PROC, backevent_proc_seal,
  297.         CANVAS_PAINTWINDOW_ATTRS,
  298.             WIN_IGNORE_EVENTS,
  299.                 KBD_DONE, KBD_USE, WIN_ASCII_EVENTS, WIN_LEFT_KEYS, WIN_TOP_KEYS,
  300.                 WIN_RIGHT_KEYS, WIN_META_EVENTS, WIN_EDIT_KEYS, WIN_MOTION_KEYS,
  301.                 WIN_TEXT_KEYS, 
  302.                 NULL,
  303.             NULL,
  304.         CANVAS_SHELL_EVENT_PROC, NULL,
  305.         WIN_CMS, infocms,
  306.         NULL);
  307.     xv_create (tile, DRAWIMAGE,
  308.         XV_X, 10,
  309.         XV_Y, 10,
  310.         XV_WIDTH, mc_width,
  311.         XV_HEIGHT, mc_height,
  312.         DRAWIMAGE_IMAGE1, mcimage,
  313.         RECTOBJ_SELECTABLE, FALSE,
  314.     RECTOBJ_EVENT_PROC, backevent_proc_seal,
  315.         NULL);
  316.     sprintf (buffer, "Midnight X Commander, version %s", VERSION);
  317.     text = (Drawtext) xv_create (tile, DRAWTEXT,
  318.         XV_X, 10,
  319.         XV_Y, mc_height + 15,
  320.         DRAWTEXT_STRING, buffer,
  321.         DRAWTEXT_FONT, xv_get (tile, XV_KEY_DATA, KEY_DATA_BOLD_FONT),
  322.         RECTOBJ_SELECTABLE, FALSE,
  323.     RECTOBJ_EVENT_PROC, backevent_proc_seal,
  324.         NULL);
  325.     height = xv_get (text, XV_HEIGHT) + mc_height + 15;
  326.     xv_create (tile, DRAWRECT,
  327.         XV_X, 10,
  328.         XV_Y, height + 2,
  329.         XV_WIDTH, xv_get (text, XV_WIDTH),
  330.         XV_HEIGHT, 4,
  331.         DRAWRECT_BORDER2, 1,
  332.         RECTOBJ_SELECTABLE, FALSE,
  333.     RECTOBJ_EVENT_PROC, backevent_proc_seal,
  334.         NULL);
  335.     tile1 = xv_create (tile, COLUMNIZER,
  336.         XV_X, 10,
  337.         XV_Y, height + 10,
  338.         COLUMNIZER_N_COLUMNS, 2,
  339.         COLUMNIZER_N_ROWS, 14,
  340.         COLUMNIZER_COLUMN_GAP, 10,
  341.         COLUMNIZER_ROW_GAP, 0,
  342.     RECTOBJ_EVENT_PROC, backevent_proc_seal,
  343.         NULL);
  344.     for (i = 0; i < 14; i++) {
  345.         xv_create (tile1, DRAWTEXT,
  346.         DRAWTEXT_STRING, names [i],
  347.             DRAWTEXT_FONT, xv_get (tile, XV_KEY_DATA, KEY_DATA_BOLD_FONT),
  348.             RECTOBJ_SELECTABLE, FALSE,
  349.         RECTOBJ_EVENT_PROC, backevent_proc_seal,
  350.             NULL);
  351.         xv_create (tile1, DRAWTEXT,
  352.             RECTOBJ_SELECTABLE, FALSE,
  353.         RECTOBJ_EVENT_PROC, backevent_proc_seal,
  354.             NULL);
  355.     }
  356.     info->widget.wdata = (widget_data) tile;
  357.     info_show_info (info);
  358.     x_info_recalculate (tile1);
  359. #endif
  360.     return 1;
  361. }
  362.  
  363.